package com.ln.asset.core.controller.admin;


import com.ln.asset.common.result.R;
import com.ln.asset.core.pojo.AssetInfo;
import com.ln.asset.core.pojo.TransferHistory;
import com.ln.asset.core.service.AssetInfoService;
import com.ln.asset.core.service.TransferHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 资产管理列表 前端控制器
 * </p>
 *
 * @author qiaoyanru
 * @since 2022-05-02
 */
@Api(tags = "资产管理")
@RestController
@RequestMapping("/admin/core/assetInfo")
public class AdminAssetInfoController {
    @Resource
    private AssetInfoService assetInfoService;
    @Resource
    private TransferHistoryService transferHistoryService;

    @ApiOperation("查询资产")
    @GetMapping("/assetList")
    public R assetList(){
        List<AssetInfo> list = assetInfoService.selectList();
        return R.ok().data("assetList",list);
    }

    @ApiOperation("根据资产id查询")
    @GetMapping("/assetById")
    public R assetById(@RequestParam(name = "list",required = false) String list){
        //System.out.println("listlistlist========"+list);
        String[] split = list.split(",");
        List<String> strings = Arrays.asList(split);
        List<AssetInfo> assetInfoList = new ArrayList<>();
        for (String string : strings) {
            int i = Integer.parseInt(string);
            AssetInfo assetInfo = assetInfoService.selectAssetById(i);
            assetInfoList.add(assetInfo);
        }
        return R.ok().data("assetInfoList",assetInfoList);
    }

    @ApiOperation("转移历史")
    @GetMapping("/histroy")
    public R histroy(){
        List<TransferHistory> transferHistories = transferHistoryService.selectHistroy();
        return R.ok().data("transferHistories",transferHistories);
    }
}

